package com.stx.utils;

import java.sql.*;

public class JDBCUtil {
    //获取链接
    public static Connection getConnection() throws SQLException {
        Connection coon = null;
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            coon = DriverManager.getConnection("jdbc:mysql:///boke?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC", "root", "000");        } catch (Exception e) {
            e.toString();
        }
        return coon;
    }

    //关闭资源
    public static void close(Connection coon, PreparedStatement preparedStatement, ResultSet resultSet) throws SQLException {
        if (coon != null) {
            coon.close();
        }
        if (preparedStatement != null) {
            preparedStatement.close();
        }
        if (resultSet != null) {
            resultSet.close();
        }
    }
}
